home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wtek0693.zip / OOPALLEY.ZIP / ASSOCINT.CPP < prev    next >
C/C++ Source or Header  |  1993-04-27  |  1KB  |  42 lines

  1. /* AssocInt.c -- implementation of key-Integer association
  2.  
  3. Function:
  4.  
  5. Objects of class AssocInt associate a key object with an Integer value
  6. object.  They are used to implement Bags, which use a Dictionary to
  7. associate objects with their occurrence counts.
  8.  
  9. */
  10.  
  11. #include "assocint.h"
  12.  
  13. #define THIS    AssocInt
  14. #define BASE    LookupKey
  15. //DEFINE_CLASS(THIS, BASE);
  16. DEFINE_CLASS(AssocInt,LookupKey);
  17.  
  18. AssocInt::AssocInt(const Object& newKey, int newValue)
  19. : LookupKey(newKey), avalue(newValue) {}
  20.  
  21. Object* AssocInt::value() const   { return (Object*)&avalue; }
  22.  
  23. Object* AssocInt::value(const Object& newValue)
  24. {
  25.     assertArgClass(newValue,class_Integer,"value");
  26.     avalue = *(Integer*)&newValue;
  27.     return &avalue;
  28. }
  29.  
  30. void AssocInt::deepenShallowCopy()
  31. {
  32.     BASE::deepenShallowCopy();
  33.     avalue.deepenShallowCopy();
  34. }
  35.  
  36. void AssocInt::printOn(ostream& strm) const
  37. {
  38.     strm << className() << "("; BASE::printOn(strm);
  39.     strm << "="; avalue.printOn(strm); strm << ")";
  40. }
  41.  
  42.